package recharge_management

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/rpc-client/assetsClient/rpc"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"
	"github.com/zeromicro/go-zero/core/logx"
)

type KbzpayListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// kbzpay--列表
func NewKbzpayListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *KbzpayListLogic {
	return &KbzpayListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *KbzpayListLogic) KbzpayList(req *types.KbzpayListRequest) (resp *types.KbzpayListResponse, err error) {
	rpcReq := rpc.KbzpayListRequest{
		Code: req.Code,
	}

	rpcResp, err := l.svcCtx.AssetsRpc.TenantChannel.KbzpayList(l.ctx, &rpcReq)
	if err != nil {
		return nil, err
	}

	kbzpayList := make([]types.Kbzpay, len(rpcResp.Records))
	for i, record := range rpcResp.Records {
		kbzpayList[i] = types.Kbzpay{
			Id:           record.Id,
			CreatedAt:    record.CreatedAt,
			UpdatedAt:    record.UpdatedAt,
			Code:         record.Code,
			Phone:        record.Phone,
			CardHolder:   record.CardHolder,
			MinAmount:    record.MinAmount,
			MaxAmount:    record.MaxAmount,
			DailyTimes:   record.DailyTimes,
			DailyAmount:  record.DailyAmount,
			RemainTimes:  record.RemainTimes,
			RemainAmount: record.RemainAmount,
			VisionLevel:  record.VisionLevel,
			IsDisplay:    record.IsDisplay,
		}
	}

	return &types.KbzpayListResponse{
		Records: kbzpayList,
		Pagination: types.Pagination{
			Page: 1,
		},
		CommonResp: types.CommonResp{
			Code:    rpcResp.CommonResp.Code,
			Message: rpcResp.CommonResp.Message,
		},
	}, nil
}
